﻿using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.VLine.InputDto;
using HCQ2_Model.VLine.OutputDto;
using HCQ2_Model.VLine.Params;
using HCQ2_Model.VR.Params;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_BLL
{
    public partial class T_VLionsRecordBLL: IT_VLionsRecordBLL
    {
        /// <summary>
        ///  VLions获取体验记录列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<RecordResult> GetRecordList(RecordModel param, out int total)
        {
            return DBSession.IT_VLionsRecordDAL.GetRecordList(param, out total);
        }
        /// <summary>
        ///  获取VLions作品排行
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<List<VLionsWorkRank>> GetProductionRank(VLionsRank model)
        {
            List<int> pList = GetLimts(model.user_id);
            return await DBSession.IT_VLionsRecordDAL.GetProductionRank(model, pList);
        }
        /// <summary>
        ///  获取VLions用户排行
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<List<VLionsUserRank>> GetUserRank(VLionsRank model)
        {
            List<int> pList = GetLimts(model.user_id);
            return await DBSession.IT_VLionsRecordDAL.GetUserRank(model, pList);
        }
        /// <summary>
        ///  获取指定用户权限
        /// </summary>
        /// <param name="user_id"></param>
        /// <returns></returns>
        private List<int> GetLimts(int user_id)
        {
            List<int> pList = new List<int>();
            if (user_id > 0)
            {
                //1.获取当前用户权限集合
                List<T_Permissions> PerList = DBSession.IT_PermissionsDAL.GetPermissById(user_id);
                if (PerList != null && PerList.Count > 0)
                    pList = PerList.Select(s => s.per_id).ToList();
            }
            return pList;
        }

        //****************************************************5.0 VLines接口【1102需求】*******************************************************
        /// <summary>
        ///  1.1 获取用户收藏目录数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetUserCollectFolderNum(UserCollectFolder model)
        {
            return await DBSession.IT_VLionsRecordDAL.GetUserCollectFolderNum(model);
        }
        /// <summary>
        ///  1.2 获取用户参加的课堂数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetUserStudyNum(UserClassRoom model)
        {
            return await DBSession.IT_VLionsRecordDAL.GetUserStudyNum(model);
        }
        /// <summary>
        ///  1.3 获取用户购买商品数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetUserPayGoodNum(UserPayGoodNum model)
        {
            return await DBSession.IT_VLionsRecordDAL.GetUserPayGoodNum(model);
        }
        /// <summary>
        ///  1.4 获取用户下载商品数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetUserDownGoodNum(UserPayGoodNum model)
        {
            return await DBSession.IT_VLionsRecordDAL.GetUserDownGoodNum(model);
        }
        /// <summary>
        ///  1.5 获取用户收藏的商品数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetUserCollectGoodNum(UserPayGoodNum model)
        {
            return await DBSession.IT_VLionsRecordDAL.GetUserCollectGoodNum(model);
        }
        /// <summary>
        ///  1.6 获取用户点赞的商品数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetUserLikeGoodNum(UserPayGoodNum model)
        {
            return await DBSession.IT_VLionsRecordDAL.GetUserLikeGoodNum(model);
        }
        /// <summary>
        ///  1.7 获取用户答题正确数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<List<UserAnswerRatioResult>> GetUserAnswerNum(UserAnswerRatio model)
        {
            List <UserAnswerRatioResult> list= await DBSession.IT_VLionsRecordDAL.GetUserAnswerNum(model);
            //if (list == null)
            //    return null;
            //list.ForEach(o =>
            //{
            //    if (o.correct > 0)
            //    {
            //        decimal correct = o.correct,
            //        total = o.total;
            //        o.accuracy = Math.Round(correct / total, 2);
            //    }
            //});
            return list;
        }
    }
}